import http from "@/api";
import { FileItemModel } from "@/api/interface/index";
export interface UserLoginSendModel {
	phone: string | number;
	password: string;
	captcha: string;
}
/** 用户登录
 */
export function userLogin(data: UserLoginSendModel) {
	return http.post<string>(`/user/login`, data);
}

export interface userGetuserInfoReturnModel {
	id: number;
	userName: string;
	phone: string;
	email: string;
	avatar: FileItemModel[];
	password: string;
	descText: string;
	addressName: string;
	province: string;
	city: string;
	county: string;
	addressDetail: string;
	createTime: number;
	updateTime: number;
	lastLoginTime: number;
	rate_count: string;

	role?: string[]; // 项目角色权限所需，暂不需要动态设定
}
/** 获得用户信息
 */
export function userGetuserInfo() {
	return http.get<userGetuserInfoReturnModel>("/user/getInfo");
}

/** 刷新token */
export function userRefreshToken() {
	return http.get<string>("/user/refreshToken");
}

interface UserModifyAccountSendModel {
	type: string;
	phone: string;
	email: string;
	newEmail: string;
	password: string;
	code: string;
	[propName: string]: any;
}
/** 根据类型修改用户的手机号、绑定邮箱、密码 */
export function userModifyAccount(data: UserModifyAccountSendModel) {
	return http.post("/user/modifyAccount", data);
}

interface UserModifySendModel {
	userName?: string;
	avatar?: string | number;
	descText?: string;
	addressName?: string;
	province?: string;
	city?: string;
	county?: string;
	addressDetail?: string;
}
/** 修改用户信息（传什么字段修改什么） */
export function userModify(data: UserModifySendModel) {
	return http.post("/user/modify", data);
}
